function Si(moduleId)
{
    this.loadImages = function()
    {
        _gel("remote_" + this.moduleId).style.backgroundColor = "#4469a9";
        _gel("topBanner").src = getCachedUrl("http://iglocalhost.googlecode.com/svn/trunk/gadgets/si.com/images/banner2.jpg");
        var banner2 = _gel("bottomBanner");
		if (banner2)
		{
			banner2.src = getCachedUrl("http://iglocalhost.googlecode.com/svn/trunk/gadgets/si.com/images/nike.jpg");
		}

		if (this.images.length == 0)
		{
	        _IG_FetchXmlContent(this.feedUrl, _IG_Callback(this.onGotImageFeed, this));
		}
		else
		{
			this.showImages(this);
		}
    }

    this.onGotImageFeed = function(xmlDoc, si)
    {

        if (xmlDoc == null)
        {
            return;
        }

        var items = xmlDoc.getElementsByTagName("item");
		//var strRegExp = 'http://([\w-]+\.)+[\w-]+(/[\w- ./]*)+\.(?:gif|jpg|jpeg|png|bmp|GIF|JPEG|JPG|PNG|BMP|Gif|Jpg|Jpeg|Png|Bmp)';
		//var rx = new RegExp( strRegExp, "g" );
		if (items.length > 0)
		{
		
			for (var i = 0; i < items.length; i++)
			{
				var enclosure = items[i].getElementsByTagName("enclosure").item(0);
				if (enclosure)
				{
					var url = enclosure.getAttribute("url");
					si.images.push(getCachedUrl(url), null);
				}
				//else
				//{
				//	var t = "" + items[i].textContent;
				//	if (rx.test(t))
				//	{
				//		var r = t.match(rx);
				//	}
				//}
			}
		}
		
		this.showImages(si);
    }

	this.showImages = function(si)
	{
		if (si.images.length > 0)
		{

			si.myShow = new Slideshow('slideShow', {hu: '', images: si.images, type: 'push', navigation:'arrows',width: si.prefs.getInt("imgSizeX"), height:si.prefs.getInt("imgSizeY"), duration: [500, 100000000]});
			si.showImage(0);
	        _IG_AdjustIFrameHeight();
		}
		else
		{
			_gel("slideShow").innerHTML = "<span style='color:red;'>Failed to retrieve images from specified feed!<span>";
		}
	}

    this.showNextImage = function(i)
    {
        var j = this.imgIndex + i;
        if (j < 0)
        {
            j = 0;
        }
        if (j >= this.images.length)
        {
            j = this.images.length - 1;
        }
        this.imgIndex = j;
        this.showImage(j);
    }

    this.next = function(timer)
    {
		var i = this.myShow.next();
		if (i != undefined)
		{
			_gel("slideLink").href = this.images[i][1];
	        this.setStatus(i);
		}

        if (timer == true)
        {
            window.setTimeout("si.next(true);", this.pause);
        }
    }

    this.random = function()
    {


    }

    this.prev = function()
    {
		var i = this.myShow.prev();
		if (i != undefined)
		{
			_gel("slideLink").href = this.images[i][1];
	        this.setStatus(i);
		}
    }

    this.showImage = function(i)
    {

        var slideImage = _gel("slideImage");
        slideImage.src = this.images[i][0];
		_gel("slideLink").href = this.images[i][1];

        this.setStatus(i);
    }

    this.setStatus = function(i)
    {
        if (!isNaN(i))
        {
            var count = _gel("count");
            if (count)
            {
                count.innerHTML = "<b>" + (i + 1) + "</b> of <b>" + (this.images.length) + "</b> images";
            }

            var caption = _gel("caption");

            if (this.images[i][2] == "")
            {
                caption.style.display = "none";
            }
            else
            {
                caption.style.display = "block";
            }

            if (caption)
            {
                caption.innerHTML = '<b><a href="' + this.images[i][1] + '">' + this.images[i][2] + ' - Click to View Full Gallery</a></b>';
            }
        }
    }

    this.pause = "4000";
    this.moduleId = moduleId;
	this.prefs = new _IG_Prefs(moduleId);
    this.images = new Array();
	var baseUrl = "http://iglocalhost.googlecode.com/svn/trunk/gadgets/si.com/images/slide/";
	this.images = [[baseUrl + "08_marisa-miller_12.jpg", "javascript:_ADS_ClickDestinationUrl('http://sportsillustrated.cnn.com/features/2008_swimsuit/models/marisa-miller/?eref=FromGGGswim08')", "Marisa Miller"],
				   [baseUrl + "08_selita-ebanks_07.jpg", "javascript:_ADS_ClickDestinationUrl('http://sportsillustrated.cnn.com/features/2008_swimsuit/models/selita-ebanks/?eref=FromGGGswim08')", "Selita Ebanks"],
				   [baseUrl + "08_bar-rafaeli_01.jpg", "javascript:_ADS_ClickDestinationUrl('http://sportsillustrated.cnn.com/features/2008_swimsuit/models/bar-refaeli/?eref=FromGGGswim08')", "Bar Refaeli"],
				   [baseUrl + "08_danika-patrick_02.jpg", "javascript:_ADS_ClickDestinationUrl('http://sportsillustrated.cnn.com/features/2008_swimsuit/danica-patrick/?eref=FromGGGswim08')", "Danica Patrick"],
				   [baseUrl + "08_body-painting.jpg", "javascript:_ADS_ClickDestinationUrl('http://sportsillustrated.cnn.com/features/2008_swimsuit/painting/?eref=FromGGGswim08')", "Bodypainting"],
				   [baseUrl + "viewall.jpg", "javascript:_ADS_ClickDestinationUrl('http://sportsillustrated.cnn.com/features/2008_swimsuit/?eref=FromGGGswim08')", ""]
				  ];
    this.imgIndex = 0;
	this.imgSize = this.prefs.getString("imgSize");
	this.feedUrl = this.prefs.getString("feedUrl");


    this.loadImages();
    window.setTimeout("si.next(true);", this.pause);

}